import 'package:flutter/material.dart';
import 'package:flutter_my_web/pages/tools/drop_draw_board/base/build_utils.dart';
import 'package:flutter_my_web/pages/tools/drop_draw_board/event/refresh_draw_board_event.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';


class DropBean {
  double width = 375;
  double height = 100;
  String desc = "组件名称";
  String name = "";
  double dy = 0;
  double dx = 0;
  int drawBoardId = -1;
  DropType type = DropType.base;
  DropBean(){
  }
  void refreshWidget(){
    refreshDrawBoard();
  }
  // AlignmentGeometry alignment = Alignment.topLeft; //位置
  // Color backColor = Colors.white; //背景色
  // EdgeInsetsGeometry padding = EdgeInsets.zero; //间距
  // EdgeInsetsGeometry margin = EdgeInsets.zero; //距离
  // BorderRadiusGeometry borderRadius = BorderRadius.circular(0); //圆角
  Function onTap = () {};
  List<Widget> bulidPropertyPanel(){
    var _heightListener = TextEditingController(text: height.toString());
    var _widthListener = TextEditingController(text: width.toString());
    _heightListener.addListener(() {
      var numStr = _heightListener.text;
      height = double.parse(numStr);
      refreshWidget();
    });
    _widthListener.addListener(() {
      var numStr = _widthListener.text;
      width = double.parse(numStr);
      refreshWidget();
    });
    List<Widget> list = [];
    list.add(Column(
        mainAxisSize:MainAxisSize.min,
      children: [
        SimpleText("基础单位"),
        Row(children: [
          SimpleText("宽度"),
          Expanded(child: TextField()),
        ],),
        SizedBox(height: 10,),
        Row(children: [
          SimpleText("高度"),
          Expanded(child: Center(child: TextField(focusNode: FocusNode()..addListener(() { }),controller: _heightListener))),
        ],),
        SizedBox(height: 10,),
      ],
    ));
    return list;
  }

  Map toJson(){
    return {
      "width":width,
      "height":height,
      "desc":desc,
      "name":name,
      "dy":dy,
      "dx":dx,
      "type":type.toStr(),
      "drawBoardId":drawBoardId,
    };
  }
  DropBean.fromJson(dynamic json) {
    width = json?['width'];
    height = json?['height'];
    desc = json?['desc'];
    name = json?['name'];
    dy = json?['dy'];
    dx = json?['dx'];
    drawBoardId = json?['drawBoardId'];
    type = getDropTypeByStr(json?["type"]);
  }
}